<template>
  <div class="app-container clearfix">  
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" >
        <el-form-item label="试题ID" prop="questionID">
          <el-input v-model="filterForm.questionID" clearable placeholder="文章ID" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="题型" prop="questionType">          
            <el-radio-group v-model="filterForm.questionType">
              <el-radio-button label="0">全部</el-radio-button>
              <el-radio-button label="1">单选</el-radio-button>
              <el-radio-button label="2">多选</el-radio-button>
              <el-radio-button label="3">简答</el-radio-button>
              <el-radio-button label="4">填空</el-radio-button>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="试题关键字" prop="keyword">
          <el-input v-model="filterForm.keyword" clearable placeholder="试题关键字" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="发布日期" prop="marketDate">
          <el-date-picker 
          clearable
            v-model="filterForm.marketDate"
            value-format="yyyyMMdd"
            type="date"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="questionStatus">          
            <el-radio-group v-model="filterForm.questionStatus">
              <el-radio-button label="0">全部</el-radio-button>
              <el-radio-button label="1">已发布</el-radio-button>
              <el-radio-button label="2">编辑中</el-radio-button>
              <el-radio-button label="3">待发布</el-radio-button>
            </el-radio-group>
        </el-form-item>
      </el-form>
      <el-button @click="handleFilter">搜索</el-button>
      <el-button @click="handleCreate()">新建</el-button>
    </div>
      <el-table
      :data="list"
      border
      style="width: 100%">
      <el-table-column
      type="selection"
      width="55">
    </el-table-column>
      <el-table-column
        prop="questionName"
        label="标题" min-width="400">
        <template slot-scope="{row}">
          <div>{{ row.questionName }}</div>
          <div>{{ row.questionCode }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="region"
        width="100"
        label="区域">
        <template slot-scope="{row}">
          <div>{{ row.regionName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="subject"
        width="100"
        label="科目">
        <template slot-scope="{row}">
          <div>{{ row.subjectName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="questionType"
        width="100"
        label="题型">
        <template slot-scope="{row}">
          <el-tag v-if="row.questionType == 1" type="info" effect="dark">单选</el-tag>
          <el-tag v-else-if="row.questionType == 2" type="info" effect="dark">多选</el-tag>
          <el-tag v-else-if="row.questionType == 3" type="info" effect="dark">简答</el-tag>
          <el-tag v-else-if="row.questionType == 4" effect="info">填空</el-tag>
          <el-tag v-else effect="dark">未定义</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="科目"
        width="100">
        <template slot-scope="{row}">
          <el-tag v-for="(subject,index) in row.subject" :key="index" style="margin-bottom:5px;margin-right:5px;">{{subject.subjectName}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="知识点"
        width="100">
        <template slot-scope="{row}">
          <el-tag v-for="(knowledge,index) in row.knowledge" :key="index" style="margin-bottom:5px;margin-right:5px;">{{knowledge.knowledgeName}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        width="100">
        <template slot-scope="{row}">
          <el-tag v-if="row.questionStatus == 1" type="danger" effect="dark">待分配</el-tag>
          <el-tag v-else-if="row.questionStatus == 2" type="warning" effect="dark">待处理</el-tag>
          <el-tag v-else-if="row.questionStatus == 3" type="info" effect="dark">已作废</el-tag>
          <el-tag v-else-if="row.questionStatus == 4" effect="dark">已添加</el-tag>
          <el-tag v-else effect="dark">未定义</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="作者"
        width="100">
        <template slot-scope="{row}">
          <span>{{row.employee.fullname}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="400">
        <template slot-scope="{row}">
            <el-button type="danger" @click="handleRemoveSubmit(row)" >删除</el-button>
            <el-button @click="handleUpdate(row.ID)" >修改</el-button>
            <el-button type="info" @click="handleCopySubmit(row)" >复制</el-button>
        </template>
      </el-table-column>
      </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />
  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getQuestionList,removeQuestion} from '@/api/examine/question'



export default {
  name: 'financeDashboard',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      list: null,
      windowHeight:"600",
      total: 0,
      listLoading: false,
      questionationList:[],
      connected:"loading",
      timer:null,
      cycleList:[],
      filterForm: {
        page: 1,
        size: 10,
        questionID:undefined,
        questionType:0,
        questionStatus:0,
        keyword: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getQuestionList(_this.filterForm).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleCreate:function(row){
      if(row == undefined){
        this.$router.push({ path: 'question-add'})
      }else{
        this.$router.push({ path: 'question-add', query: { 'parentCompanyID': row.ID }})
      }
    },
    handleUpdate:function(questionID){
        this.$router.push({ path: 'question-add', query: { 'questionID': questionID }})
    },
    handleCopySubmit:function(){},
    handleRemoveSubmit:function(question){
      let _this = this;
      removeQuestion({
        "questionID":question.ID
      }).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.getList()
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange:function(){

    }
  }
}
</script>
<style>
.filter { float: left; width: 160px; padding: 20px; min-height: 600px; }
.article { float: left; width: 800px; }
.article-item { width: 800px; height: 200px; margin-right: 25px; }
.article-item-text { float: left; width:600px; }
.article-item-icon { float: right; width:200px; height:150px; padding-left: 50px; }
.article-item-icon img { width:100%; height:100%; border-radius: 10px; }
</style>